package controller

import (
	"github.com/gin-gonic/gin"
	"k9-panel/app/adapter/internal"
	"k9-panel/app/response"
	"k9-panel/app/service"
	"net/http"
)

var (
	BaseConfig *BaseConfigController
)

func init() {
	BaseConfig = new(BaseConfigController)
}

type BaseConfigController struct {
}

func (t *BaseConfigController) Get(c *gin.Context) {
	var (
		baseRead internal.ConfigReadParam
	)
	if err := c.ShouldBind(&baseRead); err != nil {
		panic(err)
	}

	configs, err := service.BaseConfig.GetByProject(uint(baseRead.ProjectId))
	if err != nil {
		panic(err)
	}
	c.JSON(http.StatusAccepted, response.Success(configs))
	return
}
func (t *BaseConfigController) Delete(c *gin.Context) {

}
func (t *BaseConfigController) Update(c *gin.Context) {
	var (
		baseAdd internal.ConfigDataParam
	)
	if err := c.ShouldBind(&baseAdd); err != nil {
		panic(err)
	}
	create, err := service.BaseConfig.Update(uint(baseAdd.ProjectId), baseAdd.Content)
	if err != nil {
		panic(err)
	}
	c.JSON(http.StatusAccepted, response.Success(create))
}
